package com.wkhyapp.lm.view;

import android.os.Build;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wkhyapp.lm.R;
import com.wkhyapp.lm.base.BaseActivity;
import com.wkhyapp.lm.base.SuperActivity;
import com.wkhyapp.lm.contract.NoticePresenter;
import com.wkhyapp.lm.contract.NoticeView;
import com.wkhyapp.lm.http.vo.Category;
import com.wkhyapp.lm.http.vo.Notice;
import com.wkhyapp.lm.utils.MemberUtils;
import com.wkhyapp.lm.utils.PreferenceUtils;
import com.wkhyapp.lm.utils.StatusBarFontUtil;
import com.wkhyapp.lm.utils.StringUtils;
import com.wkhyapp.lm.weigit.dialog.PassWordDiaog;
import com.wkhyapp.lm.weigit.dialog.ZhuXiaoDialog;

import java.util.List;

import butterknife.BindView;

public class SettingActivity extends SuperActivity<NoticePresenter> implements NoticeView {


    @BindView(R.id.back_iv)
    ImageView back_iv;
    @BindView(R.id.hyxx_rl)
    RelativeLayout hyxx_rl;
    @BindView(R.id.yssm_rl)
    RelativeLayout yssm_rl;
    @BindView(R.id.clear_rl)
    RelativeLayout clear_rl;
    @BindView(R.id.qiehuan_rl)
    RelativeLayout qiehuan_rl;
    @BindView(R.id.xgmm_rl)
    RelativeLayout xgmm_rl;
    @BindView(R.id.zx_rl)
    RelativeLayout zx_rl;
    ZhuXiaoDialog zhuXiaoDialog = null;
    @BindView(R.id.set_tv)
    TextView set_tv;
    @Override
    public void initUI() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            translucentStatusBar();
        }
        StatusBarFontUtil.setLightStatusBarColor(this);
    }


    @Override
    protected void afterCreate() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_setting;
    }

    @Override
    protected void initListener() {
        zx_rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                zhuXiaoDialog  = new ZhuXiaoDialog(mContext);
                zhuXiaoDialog.show();
                zhuXiaoDialog.setCallBack(new ZhuXiaoDialog.callBack() {
                    @Override
                    public void jump() {
                        showLoad("正在注销");
                     mPresenter.delAccount(MemberUtils.getUid());
                    }
                });
            }
        });

        back_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        hyxx_rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            goTo(WebViewActivity.class,"http://img.wkhyw.com/yhxy.html","用户协议");
            }
        });

        yssm_rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goTo(WebViewActivity.class,"http://img.wkhyw.com/yssm.html","隐私声明");
            }
        });

        clear_rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TToast("清理成功");
            }
        });
        xgmm_rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               if(MemberUtils.isLogin()){
                   goTo(RestPwdActivity.class, MemberUtils.getMember().getPhone()+"");
               }
            }
        });

        qiehuan_rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              //  PreferenceUtils.getInstance().setPrefInt("userId",0);
                goTo(LoginActivity.class);
                finish();
            }
        });

        set_tv.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {

               final PassWordDiaog diaog = new PassWordDiaog(mContext);
                diaog.show();
                diaog.setCallBack(new PassWordDiaog.callBack() {
                    @Override
                    public void jump(String pwd) {
                        if(!StringUtils.isEmpty(pwd)){
                            if(pwd.equals("wkhy2021")){
                                goTo(AdminActivity.class);
                                diaog.close();
                            }else{
                                TToast("密码错误");
                            }
                        }else{
                            TToast("请输入密码");
                        }
                    }
                });



                return false;
            }
        });
    }

    @Override
    public void setNotice(List<Notice> list) {
        zhuXiaoDialog.close();
        TToast("注销成功!");
        PreferenceUtils.getInstance().setPrefInt("userId",0);
        goTo(LoginActivity.class);
        finish();
    }

    @Override
    public void setNoticeMore(List<Notice> list) {

    }

    @Override
    protected NoticePresenter createPresenter() {
        return mPresenter = new NoticePresenter(this);
    }
}
